#include "mainwindow.h"

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
    QFile file(":/qss/pagefold.qss");
    file.open(QFile::ReadOnly);
    QString styleSheet = QLatin1String(file.readAll());

    qApp->setStyleSheet(styleSheet);

    addSongAct = new QAction("Add Song", this);
    newPlaylistAct = new QAction("New Playlist", this);
    newPlaylistAct->setShortcut(QKeySequence::New);
    hideVideoAct = new QAction("Hide Video", this);
    hideVideoAct->setShortcut(QKeySequence("Ctrl+D"));
    exitAct = new QAction("Exit", this);

    fileMenu = menuBar()->addMenu(tr("&File"));
    fileMenu->addAction(addSongAct);
    fileMenu->addAction(newPlaylistAct);
    fileMenu->addSeparator();
    fileMenu->addAction(exitAct);

    windowMenu = menuBar()->addMenu(tr("&Window"));
    windowMenu->addAction(hideVideoAct);

    widget = new Widget(this);

    setMinimumSize(900, 500);
    setWindowTitle("SoundPool");

    //QObject::connect(addSongAct, SIGNAL(triggered()), widget, SLOT(add()));
    QObject::connect(this, SIGNAL(newPlaylist(QString)), widget, SLOT(addNewPlaylist(QString)));
    QObject::connect(newPlaylistAct, SIGNAL(triggered()), this, SLOT(addNewPlaylist()));
    QObject::connect(hideVideoAct, SIGNAL(triggered()), this, SLOT(hideVideo()));

    setWindowIcon(QIcon("icon.png"));
    setCentralWidget(widget);
}

MainWindow::~MainWindow()
{
    
}

void MainWindow::hideVideo()
{
    if(VideoPlayer::get()->isVisible())
    {
        VideoPlayer::get()->hide();
        hideVideoAct->setText("Show Video");
    }
    else
    {
        VideoPlayer::get()->show();
        hideVideoAct->setText("Hide Video");
    }

}

void MainWindow::addNewPlaylist()
{
    QInputDialog dialog(this);
    dialog.setInputMode(QInputDialog::TextInput);
    dialog.setLabelText("Name: ");
    if(dialog.exec())
    {
        QString name = dialog.textValue();
        emit newPlaylist(name);
    }
}


